package com.songVersion.services.impl;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.songVersion.model.SearchedAuthor;
import com.songVersion.services.SearchedAuthorManager;

public class SearchedAuthorManagerImpl extends CountingManagerImpl<SearchedAuthor> implements
		SearchedAuthorManager
{

	private String name;


	@Override
	public void init()
	{
		this.t = new SearchedAuthor("");
		
	}

	@Override
	protected void addHit(SearchedAuthor t)
	{
		t.setHits(t.getHits() + 1);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	protected SearchedAuthor doLoadBean(PersistenceManager pm)
	{
		Query query = pm.newQuery(SearchedAuthor.class);
		query.setFilter("name == nameParam");
		query.declareParameters("String nameParamm");
		List<SearchedAuthor> l = (List<SearchedAuthor>) query.execute(getName());
		if (l == null || l.size() == 0)
			return null;
		else
			return l.get(0);
	}

	@Override
	protected SearchedAuthor newBean()
	{
		SearchedAuthor sa = new SearchedAuthor(getName());
		return sa;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

}
